package com.wt.controller.controller.demo;

import com.wt.controller.model.base.SuccessModel;
import com.wt.service.service.demo.DemoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@Controller
@RequestMapping("demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    private final static Logger LOGGER = Logger.getLogger(DemoController.class);


    @RequestMapping("demo1")
    @ResponseBody
    public Object demo1(String userName, HttpServletRequest request)
    {
        LOGGER.info("userName="+userName);

        Map<String,Object> resultMap = demoService.demo(userName);

        return new SuccessModel(resultMap);
    }

    @RequestMapping("page/demo/user")
    @ResponseBody
    public ModelAndView user(HttpServletRequest request)
    {
        String ip = request.getRemoteAddr();
        LOGGER.info("ip :" + ip);
        return new ModelAndView("/demo/user");
    }

    @RequestMapping("page/demo/register")
    @ResponseBody
    public ModelAndView register(HttpServletRequest request)
    {
        return new ModelAndView("/demo/register");
    }

}
